package com.craftcomputing.client.Listeners;

import com.craftcomputing.client.MainPage;
import com.craftcomputing.client.Entry.EntryPanel;
import com.craftcomputing.client.SearchResult.Label.SearchResultLabel;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.ui.*;

public class SearchResultLabelListeners {
	static public class ImageLoadListener implements  LoadListener{
		private Image im;;
		public ImageLoadListener(Image im){
			this.im = im;
		}
        public void onLoad(Widget sender) {}
        public void onError(Widget sender) {
          im.setUrl("mainimages/011_11a.jpg");
        }
	}
	static public class SearchResultLabelMouseListener implements MouseListener{
		private SearchResultLabel searchResultLabel;
		private HorizontalPanel hp;
		public SearchResultLabelMouseListener(SearchResultLabel searchResultLabel, HorizontalPanel hp){
			this.searchResultLabel = searchResultLabel;			
			this.hp = hp;
		}
		public void onMouseEnter(final Widget sender) {
			hp.setStyleName("gwt-Result-Over");		   
		}
		public void onMouseLeave(final Widget sender) {
			hp.setStyleName("gwt-Result");		   
		}
		public void onMouseDown(final Widget sender, final int x, final int y){}
		public void onMouseMove(final Widget sender, final int x, final int y) {}
		public void onMouseUp(final Widget sender, final int x, final int y) {}
	}
	static public class SearchResultLabelClickListener implements ClickListener{
		private JSONValue json;
		private SearchResultLabel searchResultLabel;
		public SearchResultLabelClickListener(SearchResultLabel searchResultLabel, JSONValue json){
			this.searchResultLabel = searchResultLabel;			
			this.json = json;
		}
		public void onClick(final Widget sender){
			EntryPanel entry = searchResultLabel.makeEntryPanel();
			entry.updateEntry(json);
			MainPage.setMainPanel(entry); 
		}
	}
}
